import axios from 'axios'
// 公共 url
// var oUrl = 'http://192.168.2.194:8801/tjzcfw';//服务器 开发
var oUrl = 'http://123.232.102.30:8801/tjzcfw';//服务器 演示
// var oUrl = 'http://192.168.2.126:8801/tjzcfw';//服务器 测试
localStorage.setItem('url',oUrl)
export function oUrl(){
  return oUrl;
}
export function postAjax(urls,obj) { /*post方法*/
  return postPromise(`${oUrl}${urls}`,obj)
}
export function getAjax(urls,obj) {/*get方法*/
  return getPromise(`${oUrl}${urls}`,obj)
}
export function putAjax(urls,obj) { /*put方法*/
  return putPromise(`${oUrl}${urls}`,obj)
}
export function deleteAjax(urls,obj) {/*delete方法*/
  return deletePromise(`${oUrl}${urls}`,obj)
}
// 封装 promise
function postPromise(url,obj){
  return new Promise((resolve,reject) => {
      axios.post(url,obj).then(
        (response) =>{
          resolve(response)
        }
      ).catch(
        (err) => {
          reject(console.log(err))
        }
      )
    })
}

function getPromise(url,obj){
  return new Promise((resolve,reject) => {
      axios.get(url,{params:obj}).then(
        (response) =>{
          resolve(response)
        }
      ).catch(
        (err) => {
          reject(console.log(err))
        }
      )
    })
}
function putPromise(url,obj){
  return new Promise((resolve,reject) => {
      axios.put(url,obj).then(
        (response) =>{
          resolve(response)
        }
      ).catch(
        (err) => {
          reject(console.log(err))
        }
      )
    })
}

function deletePromise(url,obj){
  return new Promise((resolve,reject) => {
      axios.delete(url,{params:obj}).then(
        (response) =>{
          resolve(response)
        }
      ).catch(
        (err) => {
          reject(console.log(err))
        }
      )
    })
}
